<?php
/**
 * Created by PhpStorm.
 * User: yzapple
 * Date: 2018/1/25
 * Time: 上午9:43
 */

namespace app\admin\controller;


use app\common\controller\Upload;

class Plugin extends Basecontroller
{
    public function ueditor()
    {
        $action = input('get.action');
        $config = json_decode(preg_replace('/\/\*[\s\S]+?\*\//', '', file_get_contents(APP_PATH . 'common/config/ueditor_config.json')), true);
        switch ($action) {
            case 'config':
                $return = $config;
                break;
            case 'uploadimage':
                $return = $this->uploadUeditorPic();
                break;
            default:
                $return = array(
                    'state' => '请求地址出错'
                );
        }
        return json($return);
    }
    public function uploadUeditorPic()
    {
        $Upload = new Upload('upfile');
        $info = $Upload->uploadUeditorPic();
        //{"state":"SUCCESS","url":"\/ueditor\/php\/upload\/image\/20160701\/1467336066135055.jpg","title":"1467336066135055.jpg","original":"17.jpg","type":".jpg","size":178251}
        /**
         * "state" => $this->stateInfo,
         * "url" => $this->fullName,
         * "title" => $this->fileName,
         * "original" => $this->oriName,
         * "type" => $this->fileType,
         * "size" => $this->fileSize
         */
        //{"name":"17.jpg","type":"image\/jpeg","size":178251,"key":0,"ext":"jpg","md5":"a035269d024cb3ce2d3b6b11175a3182","sha1":"9f7b45b27fd280aad0dac5dadd6eefb9a628b448","savename":"201607010922576992.jpg","savepath":"\/2016-07-01\/"}
        return $info;
    }
}